import { ADD, DECREASE, CLEAR, GETDATA } from './constants.jsx'
import store from './index.jsx';
import axios from '../requests'

function addAction(payload) {
    return { type: ADD, payload };
}
function decAction(payload) {
    return { type: DECREASE, payload };
}
function clearAction(payload) {
    return { type: CLEAR, payload }
}
function getDataAction(payload) {
    return { type: GETDATA, payload }
}

function AsyncGetDataAction() {
    return async function () {
        let { data } = await axios.get('/getData');
        store.dispatch(getDataAction(data));
    }
}

export { addAction, decAction, clearAction, AsyncGetDataAction };